package com.sssre.business.exception;

import com.sssre.common.core.domain.AjaxResult;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @author 浪兎兎
 * @create 2025-04-29-12:58
 */
@RestControllerAdvice
public class BusinessGlobalExceptionHandler {
    @ExceptionHandler(MethodArgumentNotValidException.class)
    public AjaxResult ex(MethodArgumentNotValidException e) {
        return AjaxResult.error(e.getBindingResult().getAllErrors().get(0).getDefaultMessage());
    }
    @ExceptionHandler(ServiceValidException.class)
    public AjaxResult ex(ServiceValidException e) {
        return AjaxResult.error(e.getMessage());
    }
    @ExceptionHandler(Exception.class)
    public AjaxResult ex(Exception e) {
        e.printStackTrace();
        return AjaxResult.error("服务器内部异常 ε(┬┬﹏┬┬)3");
    }
}